package com.ruoyi.web.publish.dividend.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.publish.dividend.mapper.DividendMapper;
import com.ruoyi.web.publish.dividend.domain.Dividend;
import com.ruoyi.web.publish.dividend.service.IDividendService;

/**
 * 分红Service业务层处理
 *
 * @author houxuzhong
 * @date 2021-08-31
 */
@Service
public class DividendServiceImpl implements IDividendService
{
    @Autowired
    private DividendMapper dividendMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询分红
     *
     * @param id 分红主键
     * @return 分红
     */
    @Override
    public Dividend selectDividendById(Long id)
    {
        return dividendMapper.selectDividendById(id);
    }

    /**
     * 查询分红列表
     *
     * @param dividend 分红
     * @return 分红
     */
    @Override
    public List<Dividend> selectDividendList(Dividend dividend)
    {
        return dividendMapper.selectDividendList(dividend);
    }

    /**
     * 查询分红列表
     *
     * @param dividend 分红
     * @return 分红
     */
    @Override
    public List<Dividend> selectMyDividendList(Dividend dividend)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        dividend.setCreateById(user.getUserId());
        dividend.setCreateBy(user.getUserName());
        return dividendMapper.selectMyDividendList(dividend);
    }

    /**
     * 新增分红
     *
     * @param dividend 分红
     * @return 结果
     */
    @Override
    public int insertDividend(Dividend dividend)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        dividend.setCreateById(user.getUserId());
        dividend.setCreateBy(user.getUserName());
        dividend.setCreateTime(DateUtils.getNowDate());
        dividend.setPublishId(user.getUserId());
        dividend.setPublishName(user.getNickName());
        return dividendMapper.insertDividend(dividend);
    }

    /**
     * 修改分红
     *
     * @param dividend 分红
     * @return 结果
     */
    @Override
    public int updateDividend(Dividend dividend)
    {
        dividend.setUpdateTime(DateUtils.getNowDate());
        return dividendMapper.updateDividend(dividend);
    }

    /**
     * 批量删除分红
     *
     * @param ids 需要删除的分红主键
     * @return 结果
     */
    @Override
    public int deleteDividendByIds(Long[] ids)
    {
        return dividendMapper.deleteDividendByIds(ids);
    }

    /**
     * 删除分红信息
     *
     * @param id 分红主键
     * @return 结果
     */
    @Override
    public int deleteDividendById(Long id)
    {
        return dividendMapper.deleteDividendById(id);
    }
}
